<?php

/**
 * 手机短信配置
 * @author HZH
 * **/
function yunxinSendVerify($mobile,$code){
    header("Content-type: text/html; charset=utf-8");
    $client = new SoapClient("http://121.199.48.186:1210/Services/MsgSend.asmx?WSDL");
    $param = array("userCode"=>"ozkoalas","userPass"=>"Oz2016123","DesNo"=>$mobile,"Msg"=>"您的验证码是：".$code."。请不要把验证码泄露给其他人。【澳新考拉】","Channel"=>"1");
    $p = $client->__soapCall('SendMsg',array('parameters' => $param));
    return $p;
}

function getCartList($user_id,$is_checked=null){
    $cartList = [
        'cartList' => null,
        'total_amount' => 0,
        'due_amount' => 0,
        'minus_amount' => 0,
    ];
    $where = ['user_id'=>$user_id];
    if($is_checked){
        $where['is_checked'] = $is_checked;
    }
    $cartList['cartList'] = db('OrderCart')
    ->alias('oc')
    ->join('goods g','g.id=oc.goods_id','LEFT')
    ->join('GoodsAttrPrice gap','gap.goods_id=oc.goods_id and gap.key=oc.attr_key','LEFT')
    ->field('oc.*,g.image as goods_image_small,g.cate_id as cate_id,g.cost_price as goods_cost_price,g.give_integral as give_integral,gap.cost_price as gap_cost_price,gap.price as gap_price,gap.vip_price as gap_vip_price')
    ->where($where)
    ->order('goods_num asc,id desc')
    ->select();
    if($cartList['cartList']){
        foreach($cartList['cartList'] as $item){
            $cartList['total_amount'] = $cartList['total_amount'] + ($item['price']) * $item['goods_num'];
            $cartList['due_amount'] = $cartList['due_amount'] + ($item['price']) * $item['goods_num'];
            $cartList['minus_amount'] = $cartList['minus_amount'] + $item['goods_cost_price'] * $item['goods_num'];
        }
    }
    return $cartList;
}

function getGoodsAttrInfo($goods_id,$attr_array){
    $AttrInfo = db('GoodsAttrPrice')
    ->where(['goods_id'=>$goods_id,'key'=>['in',$attr_array]])
    ->find();

    $status = 0;
    $result=null;
    if($AttrInfo){
        $status = 1;
        $result = $AttrInfo;
    }

    $result = ['status'=>$status,'result'=>$result];
    return $result;
}
function orderLog($order_id,$user_id,$action_note,$status_desc){
    $info = db('Order')->where(['order_id'=>$order_id])->find();
    $time = time();
    db('OrderAction')->insert([
        'order_id'=>$order_id,
        'action_user'=>$user_id,
        'order_status'=>$info['order_status'],
        'shipping_status'=>$info['shipping_status'],
        'pay_status'=>$info['pay_status'],
        'action_note'=>$action_note,
        'log_time'=>$time,
        'status_desc'=>$status_desc
    ]);
}

?>
